from pydantic import BaseModel
from typing import Optional, List
from datetime import datetime

# 用户相关模型
class UserBase(BaseModel):
    username: str
    email: str

class UserCreate(UserBase):
    password: str

class UserLogin(BaseModel):
    username: str
    password: str

class User(UserBase):
    id: int
    created_at: datetime
    
    class Config:
        from_attributes = True

# 生辰八字相关模型
class FortuneRecordBase(BaseModel):
    birth_year: int
    birth_month: int
    birth_day: int
    birth_hour: int
    birth_minute: int
    name: Optional[str] = None
    gender: Optional[str] = None
    longitude: Optional[float] = None
    province: Optional[str] = None
    city: Optional[str] = None

class FortuneRecordCreate(FortuneRecordBase):
    pass

class FortuneRecord(FortuneRecordBase):
    id: int
    user_id: int
    year_pillar: str
    month_pillar: str
    day_pillar: str
    hour_pillar: str
    solar_year: Optional[int] = None
    solar_month: Optional[int] = None
    solar_day: Optional[int] = None
    solar_hour: Optional[int] = None
    solar_minute: Optional[int] = None
    ai_analysis: Optional[str] = None
    stage: int = 1
    created_at: datetime
    
    class Config:
        from_attributes = True

# 八字计算请求模型
class BaziCalculationRequest(BaseModel):
    birth_year: int
    birth_month: int
    birth_day: int
    birth_hour: int
    birth_minute: int
    name: Optional[str] = None
    gender: Optional[str] = None
    longitude: Optional[float] = None
    province: Optional[str] = None
    city: Optional[str] = None

# 八字计算结果模型
class BaziResult(BaseModel):
    year_pillar: str
    month_pillar: str
    day_pillar: str
    hour_pillar: str
    five_elements: dict
    analysis: str
    solar_year: Optional[int] = None
    solar_month: Optional[int] = None
    solar_day: Optional[int] = None
    solar_hour: Optional[int] = None
    solar_minute: Optional[int] = None

# AI问答请求模型
class AIQuestionRequest(BaseModel):
    record_id: int
    question: str

# JWT Token 模型
class Token(BaseModel):
    access_token: str
    token_type: str

class TokenData(BaseModel):
    username: Optional[str] = None

# AI问答响应模型
class AIQuestionResponse(BaseModel):
    answer: str
